#include "qmlcppinterface.h"
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QObject>
#include <QQuickItem>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/cutedroidmessenger/main.qml"));
    viewer.showExpanded();

    QQuickItem* item = viewer.rootObject();
    QmlCppInterface interface;

    //Conexões entre o modelo em C++ a UI:
    QObject::connect(item, SIGNAL(connect(const QString&)),
                     &interface, SLOT(connect(const QString&)));
    QObject::connect(&interface, SIGNAL(connected()),
                     item, SLOT(connectedSlot()));
    QObject::connect(&interface, SIGNAL(waitingForConnection()),
                     item, SLOT(waitingForConnSlot()));
    QObject::connect(item, SIGNAL(sendMsg(const QString&)),
                     &interface, SLOT(sendMsg(const QString&)));
    QObject::connect(&interface, SIGNAL(msgReceived(QVariant)),
                     item, SLOT(msgReceivedSlot(QVariant)));
    QObject::connect(item, SIGNAL(disconnect()),
                     &interface, SLOT(disconnect()));
    QObject::connect(&interface, SIGNAL(disconnected()),
                     item, SLOT(disconnectedSlot()));

    return app.exec();
}
